import { PrivateMsg } from '@/assets/js/entity/chat';
import { SystemMsg } from '@/assets/js/entity/system_msg';
import { Axios } from '@axios/base'
import { HttpStatus } from '@axios/base/http_status';

export class WebSocketSystemMsg extends Axios {

    constructor() {
        super('ws/system');
    }
    
    /**
     * GET /ws/system/readAll
     * 获取指定 id 用户未读取的系统消息
     * @param id 用户 id
     */
    async readSystemMsg(id: number, unread: boolean, count?: number): Promise<Array<SystemMsg>> {
        const result = await this.get<Array<SystemMsg>>('/readAll', {
            params: {
                id: id,
                unreadOnly: unread,
                count: count
            }
        });
        return result.status == HttpStatus.SUCCESS ? result.data : [];
    }

    /**
     * GET /ws/system/readed
     * 将一条系统消息变为已读   
     * @param id 消息 id
     */
    async doReadMsg(id: number): Promise<Boolean> {
        const result = await this.get<Boolean>('/readed', {
            params: {
                id: id
            }
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

}